@echo off
echo Running %0 in %CD%

rem 1=outdir 2=subdir 3=isscomponent

set cpt=%~3%
rem set iss=%~dp0%~1Files_%cpt:\=_%.iss
set iss=%~dp0%~1Files.iss


echo Listing project files to %iss%
if not exist %iss% echo [Files] > %iss%
FOR /R %CD% %%D IN (.) DO (
   echo Scanning %%D
   FOR /F %%F IN ('dir /B %%D') DO (

	FOR /F %%L IN ('find /i "%%F" %iss%') DO (
	    IF NOT "%%L" == "----------" SET found=yes
	)

	IF %%~xF==.pdb SET found=yes

	IF NOT DEFINED found (
	    echo Add "%%F" to "%iss%"
	    echo Source: "%%D\%%F"; DestDir: "{app}\%~2"; Flags: ignoreversion; Components: %~3  >> %iss%
        ) ELSE (
	    echo Skip "%%F" from "%iss%"
        )

	set found=
   )
)

echo Creating Structure %~dp0%~1%~2
if not exist %~dp0%~1%~2 mkdir %~dp0%~1%~2
if not exist %~dp0%~1%~2 exit 1

echo Publishing %CD%\*.* to %~dp0%~1%~2
xcopy /E /Y /Q %CD%\*.* %~dp0%~1%~2
